package com.tom.demo.common.enumeration;

import lombok.Getter;

@Getter
public enum ResponseEnum {

    /**
     * 成功段2000~2999
     */
    SUCCESS(2000,"操作成功"),
    LOGIN_USER_NOT_FIND(2001,"用户不存在"),
    LOGIN_USER_NOT_STATUS(2003,"用户被禁用,请联系管理员"),


    /**
     * 参数错误 5000~5999
     */
    SERVER_ERROR(5000,"服务器内部错误"),
    PARAM_REQUIRE(5003,"缺少参数"),
    PARAM_INVALID(5001,"无效参数"),
    PARAM_IMAGE_FORMAT_ERROR(5002,"图片格式有误"),
    PARAM_TYPE(5004,"参数类型匹配失败"),
    JSON_SERIALIZE_OBJECT(5005,"JSON数据序列化为对象时发生错误"),
    PARAM_CONTENT_TYPE_NO_SUPPORT(5006,"请求Content-type类型不支持"),
    OBJECT_SERIALIZE_JSON(5006,"对象序列化为JSON时发生错误"),
    REQUEST_METHOD_NOT_SUPPORTED(5007,"请求方式不支持"),
    NOT_PATH_PARAM_DETECTED(5008,"未检测到路径参数"),
    REQUEST_PARAM_BINDING_ERROR(5009,"未检测到查询参数"),
    DATABASE_OPERATION_FAILED(5010,"数据库操作失败"),
    FILE_SIZE_EXCEEDS_LIMIT(5011,"文件上传超出大小限制"),
    SOCKET_CONNECTION_TIMED_OUT(5012,"socket服务连接超时"),
    SOCKET_SERVICE_CONNECTION_FAILED(5013,"socket服务连接失败"),
    FILE_READ_WRITE_ERROR(5014,"文件IO读写错误"),
    FILE_CONTENT_TYPE_ERROR(5015,"文件格式不正确"),
    /**
     * 登录段1~100
     */
    NEED_LOGIN(1,"需要登录后操作"),
    LOGIN_PASSWORD_ERROR(2,"密码错误"),

    /**
     * token令牌相关
     */
    TOKEN_INVALID(6000,"无效的TOKEN"),
    TOKEN_EXPIRE(6001,"TOKEN已过期"),
    TOKEN_REQUIRE(6002,"TOKEN是必须的"),

    /**
     * SIGN验签 100~199
     */
    SIGN_INVALID(100,"无效的SIGN"),
    SIG_TIMEOUT(101,"SIGN已过期"),


    /**
     * 数据错误 1000~2000
     */
    DATA_EXIST(1000,"数据已经存在"),
    AP_USER_DATA_NOT_EXIST(1001,"ApUser数据不存在"),
    DATA_NOT_EXIST(1002,"数据不存在"),
    USERNAME_DATA_EXIST(1005,"账号已存在,请修改账号后提交"),
    EMAIL_DATA_EXIST(1006,"邮箱已存在,请修改邮箱后提交"),
    PHONE_NUMBER_DATA_EXIST(1007,"手机号已存在,请修改手机号后提交"),
    ROLE_NAME_DATA_EXIST(1008,"角色名称已存在,请修改角色名称后提交"),
    ROLE_KEY_DATA_EXIST(1009,"角色权限已存在,请修改角色权限后提交"),
    MENU_DATA_EXIST(1010,"当前菜单下有关联的子菜单,不能删除,请先删除其子菜单"),
    OA_PROCESS_TYPE_DATA_EXIST(1011,"当前审批类型已存在，请修改审批类型"),
    POST_NAME_DATA_EXIST(1012,"岗位名称已经存在"),
    POST_CODE_DATA_EXIST(1013,"岗位编码已经存在"),
    /**
     * 权限相关 3000~3500
     */
    NO_OPERATOR_AUTH(3000,"无权限操作"),
    NEED_ADMIN(3001,"需要管理员权限");

    private final int code;
    private final String message;

    ResponseEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据code查找对应的枚举对象，如果找不到则返回null。
     */
    public static ResponseEnum fromCode(int code) {
        for (ResponseEnum responseEnum : values()) {
            if (responseEnum.getCode() == code) {
                return responseEnum;
            }
        }
        return null; // 或者可以考虑抛出异常，表示没有匹配的枚举值
    }
}
